<?php
class GuestBook
{
   private $_gb;
   public function __construct()
   {
       $this->_gb = new Zend_Db_Table('guest_book');
   }

   function add($name, $email, $text)
   {
       $Row = $this->_gb->createRow();
       $Row->email = $email;
       $Row->name = $name;
       $Row->text = $text;
       $Row->date = new Zend_Db_Expr(" NOW() ");
       $Row->save();
       
       return $Row->ID;
   }
   
   function reject($id)
   {
       $Row = $this->_gb->find($id)->current();
       if ($Row)
       $Row->delete();
   }
   
   function approve($id)
   {
       $Row = $this->_gb->find($id)->current();
       if (!$Row) return;
       
       $Row->approved = 1;
       
       $Row->save();
   }
   
   function getOne(){
       $Row = $this->_gb->find($id)->current();
       if ($Row) return $Row->toArray();
        return false;
   }
   
   
    function setDate($id, $date){
       $Row = $this->_gb->find($id)->current();
       if (!$Row) return ;
       
       $Row->date = new Zend_Db_Expr(" DATE('$date') ");
       $Row->save();
       
   }
   
   function getList()
   {
       $Rows = $this->_gb->fetchAll(  $this->_gb->select()->order('date desc')  );
       if ($Rows) return $Rows->toArray();
       
       return array();
   }
   
   function getApprovedList()
   {
       $Rows = $this->_gb->fetchAll(  $this->_gb->select()->order('date desc')->where("approved = 1")  );
       if ($Rows) return $Rows->toArray();
       
       return array();
   }
   
    function getUnapprovedList()
   {
       $Rows = $this->_gb->fetchAll(  $this->_gb->select()->where("approved = 0")  );
       if ($Rows) return $Rows->toArray();
       
       return array();
   }
}
